// 模拟数据存储
const mockDB = {
  authToken: null,
  passwords: []
}

// 模拟API请求
const simulateRequest = (data, delay = 800) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve(data)
    }, delay)
  })
}

// 验证解锁方式
export const checkAuth = async (authData) => {
  // 实际应用中这里会调用真实API
  return simulateRequest('mock-auth-token-12345')
}

// 获取密码列表
export const getPasswords = async () => {
  return simulateRequest(mockDB.passwords)
}

// 添加新密码
export const addPassword = async (item) => {
  mockDB.passwords.push(item)
  return simulateRequest({ success: true })
}

// 更新密码
export const updatePassword = async (id, data) => {
  const index = mockDB.passwords.findIndex(p => p.id === id)
  if (index !== -1) {
    mockDB.passwords[index] = { ...mockDB.passwords[index], ...data }
  }
  return simulateRequest({ success: true })
}

// 删除密码
export const deletePassword = async (id) => {
  mockDB.passwords = mockDB.passwords.filter(p => p.id !== id)
  return simulateRequest({ success: true })
}